/*
ID: icerupt1
PROG: theme
LANG: C++11
*/

/* solution
 *
 * good mark.
 * 本来想用kmp做的，但是可能超时。
 * 其实可以二分长度在hash乱搞。。
 * 很想用串的方法，先mark good吧。
 *
*/
#include <fstream>
#include <iostream>
#include <vector>

std::ifstream fin {"theme.in" };
std::ofstream fout{"theme.out"};

int const mo = 99991;
int const maxn = 10000;
long long inverse[maxn];
int n, ans = 0;

long long inv(int a, int m)
{
	if (a == 1) return 1;
	return inv(m % a, m) * (m - m/a) % m;
}

void init_inverse()
{
	for (int i = 1; i < maxn; i++)
		inverse[i] = inv(i, mo);
}


std::vector<int> da;

bool check_theme(int p1, int p2, int len)
{
	if (p1 > p2) std::swap(p1, p2);
	if (p1 + len - 1 >= p2) return false;
	int d = da[p2] - da[p1];
	for (int i = 1; i < len; i++)
		if (da[p2 + i] - da[p1 + i] != d) return false;
	return true;
}

bool judge(int len)
{
	if (!len) return false;
	std::vector<std::vector<int>> hash(mo);
	long long h = 1;
	for (int i = 1; i < len; i++)
		h = (h * ((da[i] - da[i-1]) * (da[i] - da[i-1]) + 1)) % mo;
	hash[h].push_back(0);
	for (int i = len; i < n; i++) {
		h = (h * ((da[i] - da[i-1]) * (da[i] - da[i-1]) + 1)) % mo;
		int pos = i - len + 1;
		int tmp = da[pos] - da[pos - 1];
		h = (h * inverse[tmp * tmp + 1]) % mo;
		if (hash[h].size()) {
			for (auto p : hash[h])
				if (check_theme(p, pos, len)) return true;
		}
		hash[h].push_back(pos);
	}
	return false;
}

int main()
{
	init_inverse();
	fin >> n; da.resize(n + 2);
	for (int i = 0; i < n; i++) fin >> da[i];

	int l = 0, r = n-1;
	while (l + 1 < r) {
		int mid = (l + r) / 2;
		if (judge(mid)) l = mid;
		else			r = mid - 1;
	}
	if (judge(r)) l = r;
	if (l < 5) l = 0;
	std::cout << l << '\n';
	fout << l << '\n';
}

